<template>
  <div id="res">
    <div class="row-fluid">
      <div class="col-sm-12">
        <h3 class="page-header text-center">
          wiki管理
          <small>{{modeTitle}} (Wiki Viewer)</small>
        </h3>
      </div>
    </div>

    <div class="row">
      <div class="col-sm-12">
        <br/>
      </div>
    </div>
    <search v-show="mode=='modeList'" :mode="mode"></search>
    <node-list v-show="mode=='modeList'" :mode="mode" :method="find3" :curitems="curitems" :url="url"
               :urlwiki="urlwiki"></node-list>

    <itemedit :mode="mode" :item="{}" :on-submit="onSave" :on-cancel="onCancel"
              v-show="mode=='modeAddNew'" :method="find3" :url="url"></itemedit>

    <itemedit v-show="mode=='modeEdit'" :mode="mode" :item="curitem" :on-submit="onSave"
              :on-cancel="onCancel" :url="url"></itemedit>
    <details v-show="mode=='modeDetails'" :url="url" :item="curitem" :mode="mode" :deurl="deurl"
             :item="curitem"></details>

    <div class="row">
      <div class="col-sm-12">
        <hr/>
      </div>
    </div>

    <div class="row">
      <div class="col-sm-12 text-center">
        <span>{{curdate}}</span>
      </div>
    </div>

    <div class="row">
      <div class="col-sm-12 text-center"><br/></div>
    </div>
    <br/>

    <div class="row">
      <div class="col-sm-12">
        <hr/>
      </div>
    </div>

    <div class="row">
      <div class="col-sm-12 text-center">
        <span>{{curdate}}</span>
      </div>
    </div>
  </div>
</template>
<script>
  import Vue from 'vue'
  import resource from 'vue-resource'
  import itemedit from './edit-wiki.vue'
  import nodeList from './wikiList.vue'
  import search from './search.vue'
  import details from './view-wiki.vue'
 // import children from './fileList.vue'
  Vue.use(resource)
  export default {
    name: 'nodeViews',
    data: function () {
      return {
        currentView: 'search',
        modeTitle: '',
        curitem: {},
        curitems: [],
        criterion: '',
        pagenum: '',
        pagesteps: '',
        mode: 'modeList',
        url: 'http://euvee.vicp.co/rest/fdb/',
        urlwiki: '6efbad71-7644-468c-9773-cabcb302e676',
        item2: '',
        deurl: '',
        children: ''
      }
    },
    components: {
      nodeList,
      search,
      itemedit,
      details
    },
    methods: {
      find3: function () {
        this.$broadcast('curitems')
      },
      removeall: function (item) {
        this.$broadcast('removeitems', item)
      },
      setMode: function (newmode) {
        if (this.mode !== newmode) {
          switch (newmode) {
            case 'modeList':
              this.modeTitle = ''
              break
            case 'modeDetails':
              this.modeTitle = ' [详情]'
              break
            case 'modeEdit':
              this.modeTitle = ' [编辑]'
              break
            case 'modeAddNew':
              this.modeTitle = ' [新增]'
              this.curitem.id = null
              break
            default:
              this.modeTitle = ''
          }
          this.mode = newmode
        }
      }
    },
    events: {
      'component': function (mode) {
        this.setMode(mode)
      },
      'item': function (curitem) {
        this.curitem = curitem
      },
      'finditem': function () {
        this.find3()
      },
      'deleteitems': function (item) {
        console.log('delete all in index-node')
        this.removeall(item)
      },
      'showurl': function (url) {
        console.log('show the pic')
        this.deurl = url
      },
      'items2': function (item) {
        this.item2 = item
      },
      'onback': function () {
        this.$broadcast('onback')
      },
      'childrenitem': function (chil) {
        this.children = chil
      }
    }
  }
</script>
